const express = require('express');//引入express

const bodyParser = require('body-parser');// 引入body-parser
const users = require('./router/users');//引入路由器模块

const cors = require('cors');
const db = require('./db');
const app = express();

app.use(express.static('public'));// 静态文件托管

app.use(bodyParser.urlencoded({ extended: true }));// 应用body-parser包
app.use(cors());//解决跨域
app.use(users);//引用路由器模块
app.use('/', async (req, res) => {
    try {
        await db;
        next();
    } catch (e) {
        console.log(e);
        res.send('服务器和数据库连接失败');
    }
})
app.listen(3000, err => {
    if (!err) console.log('服务器启动成！！！');
    else console.log(err);

})